#include "TCPServer.hpp"
#include "Protocol.hpp"
#include "ServerCal.hpp"
#include "daemon.hpp"
#include <iostream>


static void Usage(std::string proc){
    std::cout << "\nUsage: " << proc << "port\n"
              << std::endl;
}

int main(int argc, char *argv[]){
    if(argc != 2){
        Usage(argv[0]);
    }
    uint16_t serverip = std::stoi(argv[1]);
    ServerCal cal;
    // 绑定一个回调函数作为参数
    TCPServer *tsvr = new TCPServer(serverip, std::bind(&ServerCal::Calculator, &cal, std::placeholders::_1));
    tsvr->InitServer();
    //Daemon();           // 守护进程化
    tsvr->StartServer();

    // Request rq(123, 456, '+');
    // std::string s;
    // rq.Serialize(&s);

    // s = Encode(s);
    // std::cout << s << std::endl;

    // Request temp;
    // std::string content;
    // Decode(s, &content);
    // std::cout << content << std::endl;
    // temp.Deserialize(content);

    // std::cout << temp._x << std::endl;
    // std::cout << temp._op << std::endl;
    // std::cout << temp._y << std::endl;

    return 0;
}